import com.google.appengine.api.datastore.*
import static com.google.appengine.api.datastore.FetchOptions.Builder.*

request.transcationTag = params.transcationTag

def transcations = []
float transcationTagTotal = 0

def query = new Query('TranscationTagE')
query.addSort('createdTime', Query.SortDirection.DESCENDING)
query.addFilter('name', Query.FilterOperator.EQUAL, params.transcationTag)
query.addFilter('userId', Query.FilterOperator.EQUAL, session.user.id)
PreparedQuery preparedQuery = datastore.prepare(query)
def ttentities = preparedQuery.asList( withLimit(Integer.MAX_VALUE) )

ttentities.each { transcationTag ->
	def transcationKey = ['TranscationE', transcationTag.transcationId]	as Key
	try {
		def transcation = datastore.get(transcationKey)
		transcationTagTotal += transcation.amount
		transcations << transcation
	} catch(Throwable t) {
		t.printStackTrace()
	}
}
request.transcations = transcations
request.transcationTagTotal = transcationTagTotal

request.title = 'Transcation View'
request.view = 'transcationViewForTag.gsp'

forward 'wydLayout.gsp'
